#region Summary

// 
// Owner : JackieHan 
// 
// Solution : DailyCollection 
// 
// Project : Jackie.Utility.Notify.Client
// 
// File : MessageProcesser.cs
// 
// CopyRight : Copyright © 2010-2011 Skomart Corporation, All Rights Reserved 
// 
// Summary : 消息处理类
// 
// History : 
//			2011-04-26 16:41:30	    Create 
// 

#endregion

#region Using

using System;
using Common.Logging;
using Jackie.Utility.Notify.Contracts;
using Jackie.Utility.Notify.Domain;

#endregion

namespace Jackie.Utility.Notify.Client
{
    public delegate void MessageArrivedHandler(object sender, MessageArrivedEventArgs e);

    public class MessageArrivedEventArgs
    {
        public MessageInfo Message { get; set; }
    }

    /// <summary> 
    /// 消息处理类
    /// </summary>
    public class MessageProcesser : IMessageCallback
    {
        public event MessageArrivedHandler MessageArrived;

        private ILog logger;

        public MessageProcesser()
        {
            logger = LogManager.GetLogger(GetType());
        }

        public void Received(MessageInfo info)
        {
            if (info.TitleCode == "KeepAlive")
            {
                logger.Info("received keep alive message!");
                return;
            }

            logger.Info("received normal message:" + info);

            if (MessageArrived != null)
                MessageArrived(this, new MessageArrivedEventArgs() { Message = info });
        }
    }
}